#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <assert.h>
#include <list>
using namespace std;

void Teststing1()
{
	string s2("hello world");
	s2.resize(20, 'x');

	s2.resize(5);

	try 
	{
		//s2[10];
		s2.at(10);
	}
	catch (const exception& e)
	{
		cout << e.what() << endl;
	}
}

void Teststing2()
{
	//
	string file("test.cpp");
	FILE* fout = fopen(file.c_str(), "r");
	char ch = fgetc(fout);

	while (ch != EOF)
	{
		cout << ch;
		ch = fgetc(fout);
	}
}

bool isNumber(char ch)
{
    return (ch >= '0' && ch <= '9');
}

int myAtoi(string str)
{
    int ret = 0;
    int flag = 1;
    int begin = 0, end = str.size();
    while (begin != end && !isNumber(str[begin]))
    {
        if (str[begin] == ' ')
        {
            ++begin;
            continue;
        }

        if (str[begin] == '+' || str[begin] == '-')
        {
            if (str[begin] == '-')
            {
                ++begin;
                flag = -1;
            }
            break;
        }
    }

    if (begin == end)
    {
        return 0;
    }

    if (str[begin] == '.')
        return 0;

    int max = INT_MAX / 10;
    while (begin != end && isNumber(str[begin]))
    {
        if (ret > max || ret == max && str[begin] > '7')
            return flag == 1 ? INT_MAX : INT_MIN;

        ret = str[begin] - '0' + ret * 10;
        begin++;
    }

    return ret * flag;
}

int main123()
{
	//Teststing1();
	//Teststing2();

    string s(".1");
    int ret = myAtoi(s);

    cout << ret;

	return 0;
}

